import type { QmsIndex } from "@/pages/qms/index/entity";
import apiClient from "../../apiClient";

export interface PageListReq {
  //检测项编码
  indexCode?: string;
  //检测项名称
  indexName?: string;
  //检测项类型
  indexType?: string;
  //当前页码
  page: number;
  //每页数量
  pageSize: number;
}

export interface PageListRes {
  //总记录数
  total: number;
  //数据列表
  records: QmsIndex[];
}

const pageList = (data: PageListReq): Promise<PageListRes> =>
  apiClient.post({
    url: "/qms/index/pageList",
    data
});

const list = (): Promise<QmsIndex[]> =>
  apiClient.get({ url: "/qms/index/list" });

const getInfo = (id: React.Key): Promise<QmsIndex> =>
  apiClient.get({
    url: `/qms/index/${id}`
});

const add = (data: QmsIndex): Promise<QmsIndex> =>
  apiClient.post({
    url: "/qms/index",
    data
});

const update = (data: QmsIndex): Promise<QmsIndex> =>
  apiClient.put({
    url: "/qms/index",
    data
});

const remove = (ids: React.Key[]): Promise<void> =>
  apiClient.delete({
    url: "/qms/index",
    params: {
    ids: ids.join(",")
  }
});
export const qmsIndexService = {
  pageList,
  list,
  getInfo,
  add,
  update,
  remove,
};

export default qmsIndexService;